package 结构型模式.装饰模式;

/**
 * 结构组成
 * 组件接口(Component)：定义对象接口，可以动态地添加职责
 * 具体组件(ConcreteComponent)：定义具体的对象，可以给它添加职责
 * 装饰器基类(Decorator)：持有一个Component对象的引用，并实现Component接口
 * 具体装饰器(ConcreteDecorator)：向组件添加具体职责
 */

interface Component
{
	int cost();
	void description(String s);
}

class Coffee implements Component
{

	@Override
	public int cost() {
		return 10;
	}

	@Override
	public void description(String s) {
		System.out.println(s);
	}
}

class SimpleCoffee implements Component
{
	private Coffee coffee;

	SimpleCoffee(Coffee coffee) {
		this.coffee = coffee;
	}

	@Override
	public int cost() {
		return coffee.cost();
	}

	@Override
	public void description(String s) {
		coffee.description(s);
	}
}

class CoffeeA extends SimpleCoffee
{
	CoffeeA(Coffee coffee) {
		super(coffee);
	}

	@Override
	public int cost() {
		return super.cost()+10;
	}

	@Override
	public void description(String s) {
		super.description("A"+s);
	}
}

class CoffeeB extends SimpleCoffee
{
	CoffeeB(Coffee coffee) {
		super(coffee);
	}

	@Override
	public int cost() {
		return super.cost()+20;
	}

	@Override
	public void description(String s) {
		super.description("B"+s);
	}
}

public class Decorator 
{
	public static void main(String[] args) {
		CoffeeA coffeeA = new CoffeeA(new Coffee());
		System.out.println("价格："+coffeeA.cost());
		coffeeA.description("咖啡");
		
		CoffeeB coffeeB = new CoffeeB(new Coffee());
		System.out.println("价格："+coffeeB.cost());
		coffeeB.description("咖啡");
	}
}